package org.xq.softcup.mq.remoting.invoker.router;

import org.xq.softcup.mq.remoting.invoker.router.impl.*;

public enum LoadBalance {
    RANDOM(new XQRpcLoadBalanceRandomStrategy()), ROUND(new XQRpcLoadBalanceRoundStrategy()),
    LRU(new XQRpcLoadBalanceLRUStrategy()), LFU(new XQRpcLoadBalanceLFUStrategy()),
    CONSISTENT_HASH(new XQRpcLoadBalanceConsistentHashStrategy());

    public final XQRpcLoadBalance xqRpcInvokerRouter;

    private LoadBalance(XQRpcLoadBalance xqRpcInvokerRouter) {
        this.xqRpcInvokerRouter = xqRpcInvokerRouter;
    }

    public static LoadBalance match(String name, LoadBalance defaultRouter) {
        for (LoadBalance item : LoadBalance.values()) {
            if (item.equals(name)) {
                return item;
            }
        }
        return defaultRouter;
    }
}
